<?php
namespace core\lib;
use core\lib\conf;
class ctrl 
 {
    public $ctrl ;
    public $action ;
    public $assign;

    public function display( $temp = null ) {

        $this->ctrl = \core\lib\route::$ctrl;
        $this->action = \core\lib\route::$action;
        if ( !is_null( $temp ) ) {           
            $temp = \explode( '/', $temp );
            if ( isset( $temp[1] ) ) {
                $this->ctrl = $temp[0];
                $this->action = $temp[1];
            } else {
                $this->action = $temp[0];
            }
        } 

        if(isset($this->assign)){
            \extract( $this->assign );
        }
        

        $file = VIEW.'/'.$this->ctrl.'/'.$this->action.conf::get('temp');
        if ( \file_exists( $file ) ) {
            include $file;
        } else {
            throw new \Exception( '找不到视图文件'.$file );

        }

    }
    /**
    * 获取变量
    */

    public function assign( $name, $value = null ) {
        if ( \is_array( $name ) ) {
            foreach ( $name as $key => $value ) {
                $this->assign[$key] = $value;
            }
        } else {
            $this->assign[$name] = $value;

        }

    }
}
